/*=============================================================================
    test/test-dom.js
    Copyright (C) 2008-2009, Donald W. Griffin
    All rights reserved.
    [MIT license :: see license.txt for details]
=============================================================================*/

function makeNode (id, className)
{
    var old = $elem(id);
    if (old && old.parentNode)
        old.parentNode.removeChild(old);

    var el = document.createElement("div");
    el.id = id;
    if (className)
        el.className = className;
    document.body.appendChild(el);
    return el;
}

gTests.push
(
    // getClasses

    function ()
    {
        makeNode("foo", "abc");
        var c = jibits.getClasses("foo");
        assertEquals(1, c.length);
        assertEquals("abc", c[0]);
    },
    function ()
    {
        makeNode("foo", "abc xyz");
        var c = jibits.getClasses("foo");
        assertEquals(2, c.length);
        assertEquals("abc", c[0]);
        assertEquals("xyz", c[1]);
    },

    // addClasses

    function ()
    {
        makeNode("foo", "abc");
        jibits.addClasses("foo", ["xyz"]);
        assertEquals("abc xyz", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo");
        jibits.addClasses("foo", ["abc", "xyz"]);
        assertEquals("abc xyz", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "xyz");
        jibits.addClasses("foo", ["abc", "xyz"]);
        assertEquals("xyz abc", $elem("foo").className);
    },

    // removeClasses

    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.removeClasses("foo", ["abc", "xyz"]);
        assertEquals("", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.removeClasses("foo", ["abc"]);
        assertEquals("xyz", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.removeClasses("foo", ["xyz"]);
        assertEquals("abc", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc mno xyz");
        jibits.removeClasses("foo", ["mno"]);
        assertEquals("abc xyz", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc mno xyz");
        jibits.removeClasses("foo", ["xyz", "mno"]);
        assertEquals("abc", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.removeClasses("foo", ["mno"]);
        assertEquals("abc xyz", $elem("foo").className);
    },

    // modifyClasses

    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.modifyClasses("foo", ["^mno"]);
        assertEquals("abc xyz mno", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.modifyClasses("foo", ["^mno"]);
        assertEquals("abc xyz mno", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.modifyClasses("foo", ["-mno", "-abc"]);
        assertEquals("xyz", $elem("foo").className);
    },
    function ()
    {
        makeNode("foo", "abc xyz");
        jibits.modifyClasses("foo", ["+mno", "-xyz"]);
        assertEquals("abc mno", $elem("foo").className);
    },

    function () { } // end of list
);
